package funcInterface.consumer;

import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

public class PredicteTest {
    public static void main(String[] args) {
        List<Integer> integers = Arrays.asList(1, 3, 4, 5, 8, 9, 10, 23);

        System.out.println("-------找到所有的奇数----------");
        Predicate<Integer> predicate = element -> element % 2 == 0 ? false : true;
        integers.stream().filter(predicate).forEach(e -> System.out.println(e));

        System.out.println("-------找到所有的偶数----------");
        Predicate<Integer> predicate1 = element -> element % 2 != 0 ? false : true;
        integers.stream().filter(predicate1).forEach(e -> System.out.println(e));

        System.out.println("-------找到所有大于5的数----------");
        Predicate<Integer> predicate3 = element -> element > 5;
        integers.stream().filter(predicate3).forEach(e -> System.out.println(e));

        System.out.println("-------找到大于10或小于4的数----------");
        Predicate<Integer> gtPredicate = element -> element > 10;
        Predicate<Integer> ltPredicate = element -> element < 4;
        integers.stream().filter(gtPredicate.and(ltPredicate)).forEach(e -> System.out.println(e));

        System.out.println("-------找到大于5或小于20的数----------");
        integers.stream().filter(gtPredicate.or(ltPredicate)).forEach(e -> System.out.println(e));

        System.out.println("---------isEqual--------");
        Person person1 = new Person(23, "m");
        Person person2 = new Person(23, "m");
        System.out.println(Predicate.isEqual(person1).test(person2));
        System.out.println(Predicate.isEqual(person2).test(person2));
    }
}
